﻿using System;
using System.Text;

namespace FinMkts
{
    /// <summary>
    /// On order to buy or sell an instrument
    /// </summary>
    public abstract class Order
    {
        /// <summary>
        /// The thing to buy or sell in a market place
        /// </summary>
        /// <remarks>
        /// TODO: This ties an order to a market place, is this correct?
        /// </remarks>
        public MarketListing Market { get; set; }
        //public FinancialInstrument Instrument { get; set; }
        //public MarketPlace MarketPlace { get; set; }

        /// <summary>
        /// The amount to buy or sell, currency is defined by the <see cref="Market"/>
        /// </summary>
        public decimal Amount { get; set; }

        /// <summary>
        /// The direction of the order: buy or sell (long or short)
        /// </summary>
        public OrderDirection Direction { get; set; }

        /// <summary>
        /// Who is the order for
        /// </summary>
        public Customer Customer { get; set; }

        //TODO: is this right?  what about other order (lifecycle) events?
        public DateTimeOffset ExecutedAt { get; set; }

        public decimal GetAmount(OrderAmountViewpoint viewPoint)
        {
            switch (viewPoint)
            {
                case OrderAmountViewpoint.Customer:
                    return Direction == OrderDirection.CustomerLong ? Amount : -Amount;
                case OrderAmountViewpoint.CounterParty:
                    return Direction == OrderDirection.CounterPartyLong ? Amount : -Amount;
                default:
                    throw new ArgumentOutOfRangeException("viewPoint");
            }
        }
    }
}
